package publisher;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JourneyDAOImpl  {
	
	Connection conn = null;
	public JourneyDAOImpl(){
		try{
			String userName = "root";
	        String password = "root";
	        String url = "jdbc:mysql://localhost/ars1";
	        Class.forName ("com.mysql.jdbc.Driver").newInstance ();
	        conn = DriverManager.getConnection (url, userName, password);
	        System.out.println ("Database connection established");
		}catch(Exception ex){
			ex.printStackTrace();
			
		}
	}
	
	public void postFlightUpdate (long flightId, String journeyDate, String message){
		CallableStatement stmt = null;
		
		System.out.println("Hi ............");
				
		try {
				stmt = conn.prepareCall("Call Postflightupdate (?,?,?)");
				stmt.setLong(1,flightId);
				stmt.setString(2, journeyDate);
				stmt.setString(3, message);
				System.out.println(stmt);
				stmt.executeUpdate();
		

		} catch (SQLException e) {
			e.printStackTrace();
		} // Very important step. Never miss out on this!
		finally {
			try {
				stmt.close();
				conn.close();
			} catch (Exception ex) {
				ex.printStackTrace();
			}

		}
		
	}
	
	
	

}
